package com.dabai.qrtools.qrcode;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.AlertDialog;

import com.dabai.qrtools.R;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

/**
 * 二维码弹窗工具类
 * @author BAI
 */
public class QRCodeDialog {

    /**
     * 显示简单的二维码对话框
     *
     * @param context 上下文
     * @param title   标题
     * @param content 内容
     * @return {@link AlertDialog}
     */
    public static AlertDialog showSimpleQrCodeDialog(Context context, String title, String content) {

        View diaView = LayoutInflater.from(context).inflate(R.layout.dialog_show_qr, null);
        ImageView imageView = diaView.findViewById(R.id.imageView);

        imageView.setImageBitmap(QRCodeUtils.createSimpleQrCodeBitmap(context,content));

        return new MaterialAlertDialogBuilder(context)
                .setTitle(title)
                .setView(diaView)
                .setPositiveButton("确认", null)
                .show();

    }
    /**
     * 显示简单的二维码对话框
     *
     * @param context 上下文
     * @param title   标题
     * @param content 内容
     * @return {@link AlertDialog}
     */
    public static AlertDialog showSimpleQrCodeDialog(Context context, String title, String content,int width,int height) {

        View diaView = LayoutInflater.from(context).inflate(R.layout.dialog_show_qr, null);
        ImageView imageView = diaView.findViewById(R.id.imageView);

        imageView.setImageBitmap(QRCodeUtils.createSimpleQrCodeBitmap(context,content,width));

        return new MaterialAlertDialogBuilder(context)
                .setTitle(title)
                .setView(diaView)
                .setPositiveButton("确认", null)
                .show();

    }


}
